<template>
	<el-card>
		<div class="course_bread_hearder">
			<div class="class-profiles">
				<div class="title">{{heardTitle}}</div>
			</div>
			<div class="float-right">
				<el-button @click="exportZip('word')" type="primary">导出word</el-button>
				<el-button @click="exportZip('pdf')" type="primary">导出pdf</el-button>
				<el-button @click="back">{{$t('common.btn.back')}}</el-button>
			</div>
		</div>
		<div style="margin-top: 8px;">
			<edu-table
				:data="schemes"
				@page-change="handleSchemeCurrentChange"
				:total="schemeForm.total_"
				:pageSize="schemeForm.pageSize_"
				:current-page="schemeForm.pageNum_"
				@selection-change="chooseScheme"
			>
				<edu-table-column :label="$t('culture.scheme.name')" >
					<template
						slot-scope="props"
					>{{($store.getters.language || 'cn')==='cn'?props.row.name:props.row.nameEn}}</template>
				</edu-table-column>
				<edu-table-column
					:label="$t('culture.scheme.faculty')"
					prop="facultyI18n"
					:render-header="labelHead"
					
				/>
				<edu-table-column
					:label="$t('course.majorCode')"
					prop="major"
					:render-header="labelHead"
					
				/>
				<edu-table-column
					:label="$t('course.majorName')"
					prop="majorI18n"
					:render-header="labelHead"
					
				/>
				<edu-table-column
					:label="$t('culture.scheme.grade')"
					prop="grade"
					:render-header="labelHead"
					
				/>
				<edu-table-column
					:label="$t('culture.scheme.trainingLevel')"
					prop="trainingLevelI18n"
					:render-header="labelHead"
					
				/>
				<edu-table-column
					:label="$t('culture.scheme.degreeType')"
					prop="degreeTypeI18n"
					:render-header="labelHead"
					
				/>
				<edu-table-column
					:label="$t('culture.scheme.formLearning')"
					prop="formLearningI18n"
					:render-header="labelHead"
					
				/>
				<edu-table-column
					:label="$t('culture.scheme.trainingType')"
					prop="trainingCategoryI18n"
					:render-header="labelHead"
					
				/>
				<edu-table-column
					:label="$t('culture.scheme.coursesType')"
					prop="label"
					:render-header="labelHead"
					
				/>
				<edu-table-column
					:label="$t('culture.scheme.degreeCourse')"
					prop="credits"
					:render-header="labelHead"
					
				/>
				<edu-table-column
					:label="$t('culture.scheme.totalScore')"
					prop="sumCredits"
					:render-header="labelHead"
					
				/>
			</edu-table>
		</div>
	</el-card>
</template>
<script>
import { queryScheme } from "common/src/api/courseTemplate";
import { exportCultureSchemePdfOrWordZip } from "common/src/api/culture/cultruescheme";
export default {
	name: "QuerySchemesComponent",
	props: {
		// 从父组件获取数据字典
		code: {
			type: String
		},
		// schemeForm: {
		// 	type: Object
		// },
		heardTitle: {
			type: String
		}
	},
	data() {
		return {
			schemeForm: {
				code: "",
				pageSize_: 20,
				pageNum_: 1,
				total_: 0
			},
			schemes: [],
			selectedSchemes:[]
		};
	},
	created() {
		this.init();
	},
	computed: {},
	methods: {
		init() {
			this.getSchemes(this.code);
		},
		getSchemes(code) {
			queryScheme(
				this.code,
				this.schemeForm.pageNum_,
				this.schemeForm.pageSize_
			).then(response => {
				if (response.code == 200) {
					this.schemes = response.data.list;
					this.schemeForm.total_ = response.data.total_;
					this.schemeForm.pageNum_ = response.data.pageNum_;
					this.schemeForm.pageSize_ = response.data.pageSize_;
				} else {
					throw response.code;
				}
			});
		},
		handleSchemeCurrentChange(val) {
			this.schemeForm.pageNum_ = val.pageNum;
			this.schemeForm.pageSize_ = val.pageSize;
			this.getSchemes();
		},
		labelHead(h, { column, $index }) {
			return h("span", { attrs: { title: column.label } }, [
				column.label
			]);
		},

		back() {
			this.$emit("back", "main");
		},
		chooseScheme(val){
			this.selectedSchemes=val;
		},
		exportZip(type){
			if(this.selectedSchemes.length==0){
				 this.$alert(
					this.$t("common.pla.plsSelectRecord"),
					this.$t("message.prompt"),
          			{ type: "warning" }
				);
				return;
			}
			let data={
                ids:this.selectedSchemes.map(scheme=>scheme.id).join(','),
                type :type               
            };
            exportCultureSchemePdfOrWordZip(data);
		}
	}
};
</script>

<style lang="scss" scoped>
.course_bread_hearder {
	height: 56px;
	cursor: default;
	.title {
		font-size: 20px;
		color: #000;
		font-weight: bold;
	}
	.class-profiles {
		float: left;
		width: 40%;
		div {
			padding: 5px 0;
		}
		.secondary-text {
			padding: 2px 0;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			font-size: 12px;
			color: #999;
		}
	}
}
</style>

